home *** CD-ROM | disk | FTP | other *** search
- Path: news.cais.com!black
- From: afbarnes@livnet.com (Andre F. Barnes)
- Newsgroups: comp.lang.c++
- Subject: MS Visual C ++ 1.52 Problem --- Global Variables
- Date: Mon, 18 Mar 96 16:08:28 GMT
- Organization: Capital Area Internet Service info@cais.com 703-448-4470
- Message-ID: <4ik1qv$15q@news.cais.com>
- NNTP-Posting-Host: black.livnet.com
- Keywords: DLL, MFC
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- HELP! HELP! HELP! with Microsoft Visual C 1.52!!!!!!
-
- Howdy out there.
-
- I need some help with an MSVC 1.52 DLL (callback) memory issue. Any
- suggestions, known related bugs, or solutions would be appreciated.
-
- THE PROBLEM:
- I am writing a standard (i.e. not extended) DLL for MSVC 1.52. Part of the
- routines for my DLL are contained in a separate .lib project. Inside this
- (.lib) project I am trying to use a modular variable. I do not have any
- problems with this modular variable until I try to reference it from within
- a callback function. OK, Am I starting to confuse you yet?
-
- DIAGRAM: (I hope your reader uses a STATIC sized font)
- EXE -> my.DLL -> my library -> third party.DLL
- ^ |
- \______________/
-
- As the diagram shows. My DLL calls a function that is inside my library,
- which I'll call Start(). That function in turn calls a third party DLL
- function, call it THIRD_PARTY_func(). The third party DLL function will in
- turn call my callback function, call it CallbackFunc().
-
- OK, After ALL that, the problem occurs. I have a global long variable that
- I now want to access from WITHIN my CallbackFunc() (see below). However, no
- matter what I do, the CallbackFunc() does not seem to know WHERE the data
- segment for that variable is. The code compiles and runs with no problems,
- but the global long value never actually changes.
-
- I know that the variable should change because I have stepped through the
- debugger NUMEROUS times. Anyway, some code snippets are below to help you
- understand what I am referring to.
-
- CODE SNIPPETS:
- typedef long (far pascal far *CallbackTypedef)();
- long gv_long;
-
- Start()
- {
- ..
- FARPROC MyCallback = MakeProcInstance((FARPROC)CallbackFunc, hInst);
- THIRD_PARTY_set_callback(id, CONSTANT, (CallbackTypedef)MyCallback);
- THIRD_PARTY_func(id);
- THIRD_PARTY_reset_callback(id, CONSTANT, REVERT_TO_DEFAULT);
- FreeProcInstance(MyCallback);
- ..
- }
-
- long far pascal _export CallbackFunc(long far *plong)
- {
- gv_long = *plong;
- }
-
- NOTES:
- I think the above should be most of the snippets that are necessary to
- understand what is happening. This problem is a DOOZY.
-
- Note that I have no problem setting the global variable outside of the
- callback function. In addition, I have other callbacks like an event
- handler for a simple C dialog that has similiar problems.
-
- I tried making the global static, using an access function to access the
- global, using a static long var within the scope of the access function.
-
- I have played with many of the compiler settings, all to no avail.
-
- FINAL NOTES:
- Just a few things that may help understand my environment. I am running Win
- 3.1 and MSVC 1.52. I am using C++ and MFC in both mydll and mylib (but I am
- NOT interfacing my dll through classes - i.e. no extended DLL stuff). I
- have the .lib and the .dll compiled using the "SS != DS, DS NOT loaded on
- function entry" option, and ALL projects are compiled with a large memory
- model.
-
- PLEASE HELP!
-
- If you have any information on the matter please email me at
- afbarnes@livnet.com Thanks!!!
-